package com.thread.test1;

/**
 * @description: TODO 类描述
 * @author: YUANG
 * @date: 2022/3/6
 **/
public class InterruptTest2 {
    public static void main(String[] args) throws InterruptedException {
        HelloThread hello = new HelloThread();
        hello.start();
        Thread.sleep(1);
        hello.running = false;
    }
}
class HelloThread extends Thread {
    //线程间共享变量需要使用volatile 为了保证全部线程都可以及时收到该状态的变化
    public volatile boolean running = true;
    public void run() {
        int n = 0;
        while (running) {
            n ++;
            System.out.println(n + " hello!");
        }
        System.out.println("end!");
    }
}
